﻿using Core.Dtos;
using Core.Domain;
using Core.IRepository;
using Core.IServices;
using Core.Messages;
using Core.Queries;
using Core.ViewModels;
using Library.Cache;
using Library.Helpers;
using Library.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Core.Mappers;
using Core.Aspects;
using Core.Context;
using Core.IRepository.Admin;

namespace Services
{
    [CacheName("Setting")]
    public class ManageSettingService : BaseService, IManageSettingService
    {
        private const string CACHE_SETTINGS = "Settings";

        private readonly IAdminRepository<int, Setting> repository;
        private readonly IAdminUnitOfWork unitOfWork;
        private readonly IGenericReaderService<int, Setting, SettingDto, SettingQuery> readerService;
        private readonly IGenericWriterService<int, Setting, SettingDto, SettingQuery> writerService;

        public ManageSettingService(IAdminUnitOfWork unitOfWork, IAdminRepository<int, Setting> repository, IGenericReaderService<int, Setting, SettingDto, SettingQuery> readerService, IGenericWriterService<int, Setting, SettingDto, SettingQuery> writerService)            
        {
            this.repository = repository;
            this.unitOfWork = unitOfWork;
            this.readerService = readerService;
            this.writerService = writerService;
            readerService.Initialize(unitOfWork, repository);
            writerService.Initialize(unitOfWork, repository);
        }
                               
        [Cache]
        public SettingDto FindByID(int id)
        {
            return readerService.FindByID(id);
        }

        public QueryResponse<SettingDto> FindBy(Request<SettingQuery> request)
        {
            return readerService.FindBy(request);
        }

        public Response<int> Add(Request<SettingDto> dto)
        {
            return writerService.Add(dto);
        }

        [DeleteCache]
        public Response Edit(int id, Request<SettingDto> dto)
        {
            return writerService.Edit(id, dto);
        }

        [DeleteCache]
        public Response Delete(int id)
        {
            return writerService.Delete(id);
        }
    }
}